home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / ResEdit / ResEdit 2.0b2 / Examples / CExamples / Source / ResEd.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-02  |  17.3 KB  |  466 lines  |  [TEXT/MPS ]

  1. /*
  2. File ResEd.h
  3.  
  4. Copyright Apple Computer, Inc. 1984-1990
  5. All rights reserved.
  6.  
  7.     Resource editor interface unit for instances of editors and pickers. This should be
  8.     included by any C implementation of a resource editor or picker.  The
  9.     companion file ResDisp.a.o should be linked with the c module to build
  10.     the file for inclusion in ResEdit.
  11.  
  12.     Pickers are given a resource type and should display all of that type in 
  13.     the current resfile in a suitable format.     If the picker is given an open call 
  14.     AND there's a compatible editor, it should give birth to the Editor.  The editor
  15.     is given a handle to the resource object and it should open up an edit
  16.     window for the user.
  17.  
  18.     Note that anybody can open pickers and editors so, for instance, a dialog item list
  19.     editor might open an icon Picker for the user to choose an appropriate icon.
  20.     The user could also, while in the icon picker, open the icon editor to create
  21.     a new icon if desired.
  22.   
  23. */
  24.  
  25. #include    <types.h>
  26. #include    <quickdraw.h>
  27. #include    <lists.h>
  28. #include    <controls.h>
  29. #include    <windows.h>
  30. #include    <events.h>
  31. #include    <dialogs.h>
  32. #include    <printing.h>
  33.  
  34. /* Standard menus exported by ResEdit */
  35.  
  36. #define    fileMenu         2
  37.  
  38. #define    newFileItem     1
  39. #define    openFileItem    2
  40. #define    openSpecialItem 3
  41. #define    closeItem       4
  42. #define    saveItem         5
  43. #define    revertItem        6
  44. #define    getThisInfoItem 8
  45. #define    getInfoItem     9
  46. #define    verifyItem         10
  47. #define    pageSetupItem   12
  48. #define    printItem        13
  49. #define    preferencesItem    15
  50. #define    quitItem        17
  51.     
  52.     // Masks for AbleMenu - normally not used directly.
  53. #define    newFileMask        0x2
  54. #define    openFileMask    0x4
  55. #define openSpecialMask    0x8
  56. #define    closeMask        0x10
  57. #define    saveMask        0x20
  58. #define    revertMask        0x40
  59. #define    getThisInfoMask 0x100
  60. #define    getInfoMask        0x200
  61. #define    verifyMask        0x400
  62. #define    pageSetupMask    0x1000
  63. #define    printMask        0x2000
  64. #define    preferencesMask 0x8000
  65. #define    quitMask        0x20000
  66. #define    disabledMask    0x1
  67.  
  68.     // Mask combinations to be used in calls to AbleMenu.
  69. #define    fileNotOpen        disabledMask + newFileMask + openFileMask + openSpecialMask + getInfoMask + verifyMask + pageSetupMask + preferencesMask + quitMask
  70. #define    fileNoPrint        fileNotOpen + getThisInfoMask + closeMask + saveMask + revertMask
  71. #define    fileAll            fileNoPrint + printMask
  72. #define    fileDA            disabledMask + closeMask + quitMask
  73.  
  74. #define    rsrcMenu                128
  75.     
  76. #define    rsrcCreateItem            1
  77. #define    rsrcOpenItem            2
  78. #define    rsrcOpenTemplateItem    3
  79. #define    rsrcOpenHexItem            4
  80. #define    rsrcRevertItem            6
  81. #define    rsrcGetInfoItem            8
  82.     
  83. #define    rsrcCreateMask            0x2
  84. #define    rsrcOpenMask            0x4
  85. #define    rsrcOpenTemplateMask    0x8
  86. #define    rsrcOpenHexMask            0x10
  87. #define    rsrcRevertMask            0x40
  88. #define    rsrcGetInfoMask            0x100
  89. #define    rsrcDisabledMask        0xFFFFFE01
  90.     
  91. #define    rsrcDisabled            0xFFFFFE00
  92. #define    rsrcRevertOnly            rsrcDisabledMask + rsrcRevertMask
  93. #define    rsrcPickerNoSel            rsrcDisabledMask + rsrcCreateMask
  94. #define    rsrcFilePicker            rsrcPickerNoSel + rsrcRevertMask + rsrcOpenMask
  95. #define    rsrcRsrcPicker            rsrcFilePicker + rsrcOpenHexMask + rsrcOpenTemplateMask + rsrcGetInfoMask
  96. #define    rsrcEditor                rsrcDisabledMask + rsrcRevertMask + rsrcGetInfoMask
  97. #define    rsrcEditorPicker        rsrcEditor + rsrcOpenMask + rsrcOpenTemplateMask + rsrcOpenHexMask
  98. #define    rsrcDITLEd                rsrcEditorPicker - rsrcOpenHexMask + rsrcCreateMask
  99. #define    rsrcEditorCreate        rsrcEditor + rsrcCreateMask
  100.  
  101. #define    editMenu            3
  102.  
  103. #define    undoItem            1
  104. #define    cutItem             3
  105. #define    copyItem            4
  106. #define    pasteItem            5
  107. #define    clearItem            6
  108. #define    dupItem             8
  109. #define selectAllItem        9
  110. #define selectChangedItem    10
  111.  
  112. /* Masks for AbleMenu - normally not used directly. */
  113. #define undoMask            0x2
  114. #define cutMask                0x8
  115. #define editCopyMask        0x10
  116. #define pasteMask            0x20
  117. #define clearMask            0x40
  118. #define duplicateMask        0x100
  119. #define selectAllMask        0x200
  120. #define selectChangedMask    0x400
  121. #define editDisabledMask     0xFFFFF801
  122.  
  123. /* Mask combinations to be used in calls to AbleMenu. */
  124. #define editNone            editDisabledMask - 1
  125. #define editClear            editDisabledMask + clearMask
  126. #define editCopy            editDisabledMask + editCopyMask
  127. #define editPaste            editDisabledMask + pasteMask
  128. #define editUndoPasteOnly    editPaste + undoMask
  129. #define editDup                editClear + duplicateMask
  130. #define editNoDup            editDisabledMask + cutMask + editCopyMask + pasteMask + clearMask /* No dup or undo */
  131. #define editNoUndo            editNoDup + duplicateMask
  132. #define editUndNoDup        editNoDup + undoMask
  133. #define editAll                editNoUndo + undoMask
  134. #define editAcc             editUndNoDup            /* for DAs */
  135.  
  136. #define viewMenu 130            /* Type pickers view menu. */
  137.     
  138. #define viewByIDItem            1
  139. #define viewByNameItem            2
  140. #define viewBySizeItem            3
  141. #define viewByOrderItem            4
  142. #define viewBySpecialItem        5
  143. #define viewShowAttributesItem    7
  144.     
  145. /* Masks for AbleMenu. */
  146. #define viewByIDMask            0x2
  147. #define viewByNameMask            0x4
  148. #define viewBySizeMask            0x8
  149. #define viewByOrderMask            0x10
  150. #define viewBySpecialMask        0x20
  151. #define viewShowAttributesMask    0x40
  152. #define viewDisabledMask        0xFFFFFF81
  153.     
  154. #define viewNoSpecial            viewDisabledMask + viewByIDMask + viewByNameMask + viewBySizeMask + viewByOrderMask
  155. #define viewNoAttributes        viewNoSpecial + viewBySpecialMask
  156. #define viewAll                    viewNoAttributes + viewShowAttributesMask
  157.  
  158. #define editorNameChr 0        /* First char of the name for editors */
  159.     
  160. /* Standard strings available by calling GetStr. */
  161. #define editStrings        130            /* Resource ID of STR# resource containing the strings. */
  162. #define undoChangeStr    1
  163. #define redoChangeStr    2
  164. #define undoCutStr        3
  165. #define redoCutStr        4
  166. #define undoCopyStr        5
  167. #define redoCopyStr        6
  168. #define undoClearStr    7
  169. #define redoClearStr    8
  170. #define undoTypingStr    9
  171. #define redoTypingStr    10
  172. #define undoPasteStr    11
  173. #define redoPasteStr    12
  174. #define undoStr            13
  175.     
  176. #define miscStrings                129    /* Resource ID of STR# resource containing the strings. */
  177. #define miscStringsName "\pMisc"
  178. #define fromStr                    1        /* String for window titles. */
  179. #define cantLoadSndErrStr        24        /* Snd picker error. */
  180. #define fullWindowStr             38        /* String for the resizeWind menu item */
  181. #define ownerWindowWindowStr    39
  182. #define newItemStr                 40        /* Enter new item number */
  183. #define selectItemStr             41        /* Open which item? */
  184. #define clipBoardErrorStr        42        /* Error accessing the Clipboard. */ 
  185. #define sndErrorStr                43        /* Error playing a sound. */
  186. #define openUsingStr            44        /* Open using Template… */
  187. #define openAsDITMStr            45        /* Open As Dialog Item */
  188. #define openDITMStr                77        /* Open Item */
  189.  
  190. /* Text for selected errors */
  191. #define errorStrings        132        /* Resource ID of STR# resource containing the error strings */
  192. #define errorStringsName "\pErrors"
  193. #define genericErrStr            1    /* Returned by GetErrorText when no specific message available */
  194. #define ioErrStr                1
  195. #define writeProtectErrStr        2
  196. #define diskFullErrStr            3
  197. #define fileLockedErrStr        4
  198. #define outOfMemoryErrStr        5
  199. #define alreadyOpenErrStr        6
  200. #define tooManyOpenErrStr        7
  201. #define volNotMountedErrStr        8
  202. #define resNotFoundErrStr        9
  203. #define accessErrStr            10
  204. #define resFileNotFoundErrStr    11
  205. #define addResFailErrStr        12
  206. #define removeResFailErrStr        13
  207. #define resAttributesErrStr        14
  208. #define resMapErrStr            15    
  209. #define fileNotFoundErrStr        16
  210. #define eofErrStr                17
  211.  
  212. #define arrowCursor -1    /* Used in the call to SetTheCursor to set the arrow cursor. */
  213.  
  214. #define minPickStdWidth     150
  215. #define minPickStdHeight    64
  216.  
  217. #define theScrollBar 15                    /* Width of a scroll bar. */
  218. #define pickerGaps 6;                    /* 4 bet graphic & frame, 2 for frame */
  219.  
  220. #define okChoice 1
  221.     
  222. #define noDialog 0
  223.     
  224. #define alertStringsName "\pAlert strings"
  225. #define badCharAlert 1                    /* ALRT, DLOG, WIND editors */
  226. #define revertResourceAlertStr 2
  227. #define noTemplateAlert 6                /* GNRL editor */
  228. #define cantPlayOnThisMachineAlert 7    /* snd picker */
  229. #define cantPlaySndAlert 8                /* snd picker */
  230.  
  231. /* Consts for Resource menu string */
  232. #define rsrcStrName         "\pResource menu"
  233. #define rsrcCreateStr         1
  234. #define rsrcOpenStr         2
  235. #define rsrcListStr         3
  236. #define rsrcOpenLists         4
  237. #define rsrcOpenEditor         5
  238. #define rsrcOpenEditors     6
  239. #define rsrcOpenHex         7
  240. #define rsrcRevert             8
  241. #define rsrcRevertThese     9
  242. #define rsrcResources         10
  243. #define rsrcRevertRes         11
  244. #define rsrcRevertThis         12
  245. #define rsrcPatCreateStr     13
  246. #define rsrcSICNCreateStr    14
  247. #define rsrcDITLCreateStr    15
  248. #define rsrcRevertItemStr    16
  249. #define rsrcGNRLCreateStr    17
  250.     
  251. /* ViewTypes to be used with the viewBy item in the PickRec */
  252. #define viewById        0
  253. #define viewByName        1
  254. #define viewBySize        2
  255. #define viewByOrder        3
  256. #define viewBySpecial    4
  257.  
  258. /* Alert kinds used by the DisplayAlert procedure. */
  259.  
  260.     typedef enum { displayTheAlert, displayStopAlert, displayNoteAlert, displayCautionAlert, 
  261.                    displayYNAlert, displayYNCAlert, displayYNCStopAlert } AlertType;
  262.  
  263. /* private string type }
  264.  
  265.     typedef unsigned char Str64[65];
  266.  
  267. /* map entry definition for new resource manager call */
  268.     typedef struct {
  269.            short        rID;
  270.         short        rNameOff;
  271.         long        rLocn;
  272.         Handle        rHndl;
  273.     } ResMapEntry;
  274.  
  275.     /* This structure is used by the GetQuickDrawVars procedure. */
  276.     typedef struct  {
  277.         long     randSeed;
  278.         BitMap     screenBits;
  279.         Cursor     arrow;
  280.         Pattern dkGray;
  281.         Pattern ltGray;
  282.         Pattern gray;
  283.         Pattern black;
  284.         Pattern white;
  285.         GrafPtr thePort;
  286.     } QuickDrawVars;
  287.     typedef    QuickDrawVars    *pQuickDrawVars;
  288.     
  289.     /* Each driver has its own object handle. This has to start with a handle
  290.         to its parent's object followed by the name distinguishing the father
  291.         This name will be part of the son's window title. The next field should
  292.         be the window of the obj (may be used by son to get back to the father
  293.         (through the refcon in the windowRec). The next field is the rebuild flag
  294.         used to indicate that a windows data (e.g. a pickers list) needs to be
  295.         recalculated at the next opportunity.  The rest of the handle can be of
  296.         any format.  The name for pickers should be the name of the file or disk.
  297.         For editors, the name should be the complete name (not the windows title)
  298.         preceded by an editorNameChr character (see const above).  An example of a
  299.         complete name would be "ALRT ID = -1234 from AFile".  This name is used to
  300.         uniquely identify a window. 
  301.         
  302.         See the manual for detailed documentation of this interface file. */
  303.  
  304.     typedef    struct ParentRec {
  305.         struct    ParentRec    **father;
  306.         Str255                name;        /* Max 255 characters */
  307.         WindowPeek            wind;
  308.         Boolean                rebuild;    /* flag set by son to indicate that world         */
  309.                                         /* has changed so father should rebuild list     */
  310.     } ParentRec;
  311.     
  312.     typedef    ParentRec    *ParentPtr;
  313.     typedef    ParentPtr    *ParentHandle;
  314.  
  315. /* Standard picker record */
  316.  
  317.     typedef struct PickRec {
  318.         ParentHandle        father;            /* Back ptr to dad             */
  319.         Str255                fName;            /* Max 255 characters.         */         
  320.         WindowPtr            wind;            /* Directory window         */
  321.         Boolean                rebuild;
  322.         short                pickID;            /* ID of this picker         */
  323.         ResType                rType;            /* Type for this picker     */
  324.         short                rNum;            /* resfile number             */
  325.         long                rSize;            /* size of a null resource     */
  326.         short                nInsts;            /* Number of instances         */
  327.         ListHandle            instances;        /* List of instances         */
  328.         Ptr                    drawProc;        /* List draw proc             */
  329.         ControlHandle        scroll;            /* Scroll bar                 */
  330.         short                viewBy;            /* Current view type        */
  331.         ResType                ldefType;        /* Which LDEF to use        */
  332.         MenuHandle            theViewMenu;    /* The picker view menu        */
  333.         Boolean                showAttributes;    /* Show attrs in window?    */
  334.         long                viewMenuMask;    /* Which items are enabled?    */
  335.         Cell                cellSize;        /* Size for special view.    */
  336.     } PickRec;
  337.     
  338.     typedef    PickRec    *PickPtr;
  339.     typedef    PickPtr    *PickHandle;
  340.  
  341.     typedef pascal void (*DrawResProcPtr) (Rect *lRect, Handle theIcon);
  342.  
  343.  
  344. /* These routines are used to start pickers and editors.*/
  345.  
  346. pascal void            GiveEBirth(Handle resHandle, PickHandle pick);
  347. pascal void            GiveThisEBirth(Handle resHandle, PickHandle pick, ResType openThisType);
  348. pascal void            GiveSubEBirth(Handle resHandle, PickHandle pick);
  349.  
  350. /* These routines are used to feed events and menu calls to the appropriate picker or editor. */
  351.  
  352. pascal void            CallInfoUpdate(short oldID, short newID, long object, short id);
  353. pascal void         PassMenu(short menu, short item, ParentHandle father);
  354.  
  355. /* Window Utilities */
  356.  
  357. pascal Boolean        AlreadyOpen (StringPtr windowTitle, StringPtr windowName, ParentHandle father);
  358. pascal WindowPtr    PickerWindSetup (Boolean color, short width, short height, StringPtr windowTitle,
  359.                                        short windowKind, ParentHandle father);
  360. pascal WindowPtr    EditorWindSetup (short dlogID, Boolean color, short width, short height, StringPtr windowTitle, 
  361.                                      StringPtr windowName, Boolean addFrom, short windowKind, ParentHandle father);
  362. pascal void            GetWindowTitle (StringPtr windowTitle, StringPtr windowName, Boolean addFrom,
  363.                                     ParentHandle father);
  364. pascal void            SetETitle(Handle h, StringPtr str);
  365. pascal WindowPtr    WindAlloc(void);
  366. pascal void            WindReturn(WindowPtr w);
  367. pascal ListHandle    WindList(WindowPtr w, short nAcross, Point cSize, short drawProc);
  368. pascal void            WindOrigin(WindowPtr w, ParentHandle father);
  369.  
  370.  
  371. /* Extended Resource Manager */
  372.  
  373. pascal short        CurrentRes(void);
  374. pascal Handle        Get1Index(ResType, short index);
  375. pascal Handle        Get1Res(ResType, short id);
  376. pascal Handle        ResEditGet1Resource (ResType theType, short id, Boolean *wasLoaded, short *error);
  377. pascal Boolean        NeedToRevert (WindowPtr myWindow, Handle theRes);
  378. pascal void            RemoveResource (Handle theRes);
  379. pascal Boolean        RevertThisResource (ParentHandle theObj, Handle theRes);
  380. pascal Boolean        RestoreRemovedResources (PickHandle pick);
  381. pascal void            ResourceIDHasChanged (ParentHandle theObj, ResType theType, short theOldId, short theNewId);
  382. pascal short        SysResFile(void);
  383. pascal short        BeautifulUnique1ID (ResType t);
  384.  
  385.  
  386. /* Miscellaneous utilities */
  387.  
  388. pascal void            Abort(void);
  389. pascal void            AbleMenu(short menu, long enable);
  390. pascal Boolean        AddNewRes(Handle hNew, ResType t, short idNew, StringPtr s);
  391. pascal void            BubbleUp(Handle);
  392. pascal short        BuildType(ResType t, ListHandle l);
  393. pascal Boolean        CheckError(short err, short msgID);
  394. pascal Boolean        CloseNoSave(void);
  395. pascal void            ConcatStr(StringPtr str1, StringPtr str2);
  396. pascal short        DefaultListCellSize(void);
  397. pascal void            CenterDialog (ResType theType, short dialog);
  398. pascal Boolean        DisplaySTRAlert(AlertType which, StringPtr STRName, short STRIndex);
  399. pascal short        DisplayAlert(AlertType which, short id);
  400. pascal Boolean        DoPickBirth(Boolean color, Boolean buildList, short wWidth, short wHeight,
  401.                                 short columns, short pickerResId, PickHandle pick);
  402. pascal void            DrawLDEF (short message, Boolean lSelect, const Rect *lRect, Handle theRes,
  403.                               short id, StringPtr title, short maxH, short maxV, 
  404.                               DrawResProcPtr DrawResource, ListHandle lh);
  405. pascal void            DrawMBarLater(Boolean forceItNow);
  406. pascal WindowPtr    FindOwnerWindow (Handle theRes);
  407. pascal void            FixHand(long s, Handle h);
  408. pascal void            FlashDialogItem (DialogPtr dp, short item);
  409. pascal void            FrameDialogItem (DialogPtr dp, short item);
  410. pascal pQuickDrawVars GetQuickDrawVars(void);
  411. pascal void            GetStr(short num, short list, StringPtr str);
  412. pascal void            GetNamedStr(short index, StringPtr name, StringPtr str);
  413. pascal void            GrowMyWindow (short minWidth, short minHeight, WindowPtr windPtr, ListHandle);
  414. pascal Boolean        HandleCheck(Handle h, short msgID);
  415. pascal void            MetaKeys(Boolean *cmd, Boolean *shift, Boolean *opt);
  416. pascal Handle        NewRes(long s, ResType t, ListHandle l, short *n);
  417. pascal void            PickEvent(EventRecord *evt, PickHandle pick);
  418. pascal void            PickInfoUp(short oldID, short newID, PickHandle pick);
  419. pascal void            PickMenu(Boolean tossOnClose, short menu, short item, PickHandle pick);
  420. pascal short        PickStdHeight(void);
  421. pascal short        PickStdWidth(void);
  422. pascal Handle        PrintSetup(void);        /* Return type is actually THPrint */
  423. pascal void            PrintWindow (PicHandle toPrint);
  424. pascal short        ResEdID(void);
  425. pascal void            SendRebuildToPicker (ResType theType, ParentHandle parent);
  426. pascal void            SendRebuildToPickerAndFile (ResType theType, ParentHandle parent) ;
  427. pascal void            SetResChanged(Handle h);
  428. pascal void            SetTheCursor (short whichCursor);
  429. pascal void            ShowInfo(Handle h, ParentHandle father);
  430. pascal void            TypeToString(ResType t, StringPtr s);
  431. pascal void            UseAppRes(void); 
  432. pascal Boolean        WasAborted(void);
  433. pascal Boolean        WasItLoaded(void);
  434. pascal Boolean        ColorAvailable(void);
  435.  
  436. /* Color Palette Popup Menus */
  437.  
  438. pascal void            InstallColorPalettePopup( WindowPtr whichWindow, Boolean CQDishere,
  439.                                               Boolean isActive );
  440. pascal void            DrawColorPopup( WindowPtr whichWindow, Rect *itemBox,
  441.                           RGBColor *whichColor, Boolean CQDishere );
  442. pascal Boolean        ColorPalettePopupSelect( WindowPtr whichWindow, Rect *itemBox,
  443.                           RGBColor *whichColor, Boolean CQDishere );
  444. pascal void            DeinstallColorPalettePopup( WindowPtr whichWindow, Boolean CQDishere );
  445.     
  446. /* Routines that are used internally withing ResEdit and may be useful in other
  447.     circumstances. */
  448.     
  449. pascal ResType        MapResourceType (Boolean editor, Handle theRes, ResType origResType);
  450. pascal void            DoKeyScan(EventRecord *evt, short offset, ListHandle lh);
  451. pascal Handle        DupPick(Handle h, Cell c, PickHandle pick);
  452. pascal Boolean        GetType(Boolean templatesOnly, StringPtr s);
  453. pascal void            KillCache(void);
  454. pascal void            RCalcMask(Ptr srcPtr, Ptr dstPtr,
  455.                            short srcRow, short dstRow, short height, short words);
  456. pascal short        ResEditRes(void) =
  457.                     {0x3eB8, 0x0900};    /* move.w    CurApRefNum,(sp) */
  458. pascal void            ScrapCopy(Handle *h);
  459. pascal void            ScrapEmpty(void);
  460. pascal void            ScrapPaste(Boolean pasteAll, ResType typeToPaste, short resFile);
  461. pascal void            WritePreferences (ResType prefType, short prefId, Str255 prefName, Handle prefHandle);
  462. pascal void            GetErrorText (short error, StringPtr errorText);
  463. pascal Boolean        PlaySyncSound(short which, Handle sndHandle);
  464.  
  465.  
  466.